package cn.eonshine.cuba.inf.modular.biz.service.impl;

import java.util.Date;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import cn.eonshine.cuba.inf.common.http.InfStatus;
import cn.eonshine.cuba.inf.modular.biz.entity.InventoryData;
import cn.eonshine.cuba.inf.modular.biz.mapper.InventoryDataMapper;
import cn.eonshine.cuba.inf.modular.biz.service.IInventoryDataService;
import cn.eonshine.cuba.inf.modular.common.service.AbstractCommonService;

/**
 * <p>
 * Inventory data（每日库存表） 服务实现类
 * </p>
 *
 * @author Alan
 * @since 2018-07-28
 */
@Service
@Transactional
public class InventoryDataServiceImpl extends AbstractCommonService<InventoryDataMapper, InventoryData> implements IInventoryDataService {
	
	
	/**   
	 * <p>Title: customerQueryWrapper</p>   
	 * <p>Description: </p>   
	 * @see cn.eonshine.cuba.inf.modular.common.service.AbstractCommonService#customerQueryWrapper()   
	 * @author: Alan
	 * @date:   2019-03-25 21:58:29
	 */
	@Override
	public QueryWrapper<InventoryData> customerQueryWrapper() {
		QueryWrapper<InventoryData> entity = new QueryWrapper<InventoryData>();
		entity.lambda().eq(InventoryData::getLsmsUpdate, InfStatus.LSMS_UPDATE_EXTRACT_NO);
//		entity.orderByAsc("ORG_ID,OILCAN_ID,OIL_ID,DATA_INPUT_DATETIME");
		entity.lambda().orderByAsc(InventoryData::getOrgId, InventoryData::getOilcanId, InventoryData::getOilId, InventoryData::getRptDate, InventoryData::getDataInputDatetime);
		return entity;
	}



	/**   
	 * <p>Title: transportDataHandle</p>   
	 * <p>Description: </p>   
	 * @param inventoryData
	 * @param count
	 * @throws Exception   
	 * @see cn.eonshine.cuba.inf.modular.common.service.AbstractCommonService#transportDataHandle(java.lang.Object, int)   
	 * @author: Alan
	 * @date:   2019-03-25 21:58:29
	 */
	@Override
	public int transportDataHandle(InventoryData inventoryData, int count) throws Exception {
		String orgId = inventoryData.getOrgId();
		String oilCanId=inventoryData.getOilcanId();
		String oilId=inventoryData.getOilId();
		Date dataInputDatetime = inventoryData.getDataInputDatetime();
		
		QueryWrapper<InventoryData> entity = new QueryWrapper<InventoryData>();
//		entity.where("ORG_ID={0} and OILCAN_ID={1} and OIL_ID={2} and DATA_INPUT_DATETIME={3}", orgId,oilCanId,oilId, dataInputDatetime);
		entity.lambda().eq(InventoryData::getOrgId, orgId);
		entity.lambda().eq(InventoryData::getOilcanId, oilCanId);
		entity.lambda().eq(InventoryData::getOilId, oilId);
		entity.lambda().eq(InventoryData::getDataInputDatetime, dataInputDatetime);
		
		boolean isSuccess = false;
		if(this.isUpdate==0){
			isSuccess = remove(entity);
		}else {
			isSuccess = update(inventoryData, entity);
		}
		if(isSuccess) {
			count ++;
		}
		return count;
	}



	/**   
	 * <p>Title: mappingHandle</p>   
	 * <p>Description: </p>   
	 * @param obj
	 * @throws Exception   
	 * @see cn.eonshine.cuba.inf.modular.common.service.AbstractCommonService#mappingHandle(java.lang.Object)   
	 * @author: Alan
	 * @date:   2019-03-25 21:58:29
	 */
	@Override
	public void mappingHandle(InventoryData obj) throws Exception {
		// TODO Auto-generated method stub
		
	}



	/**   
	 * <p>Title: isUseCutomerSelectSQL</p>   
	 * <p>Description: </p>   
	 * @see cn.eonshine.cuba.inf.modular.common.service.AbstractCommonService#isUseCutomerSelectSQL()   
	 * @author: Alan
	 * @date:   2019-03-25 21:58:29
	 */
	@Override
	public boolean isUseCutomerSelectSQL() {
		return true;
	}


}
